define (require, exports, module) ->
  require 'mods/info_side/info_side_css.css'

  infoSideApi = require 'mods/info_side/info_side_api'

  module.exports = Vue.extend

    # 组件模板
    template: require 'mods/info_side/info_side_tpl.js'

    # 定义变量
    data: () ->
      # 个人中心menu数组
      infoMenus: [
        {'name':'账户中心', 'url':'/user_info'}
        {'name':'我的产品', 'url':'/info_prod'}
        {'name':'订单管理', 'url':'/info_order'}
        {'name':'定制产品', 'url':'/custom_prod'}
      ]
      # 当前导航,改变菜单样式
      curMenu: 0
      # 个人信息
      userInfo: {}
      # 资金信息
      fundInfo: {}

    # 定义方法
    methods:

      # 切换个人中心左侧栏菜单
      checkMenu: (curUrl, index) ->
        self = @
        self.curMenu = index
        self.$router.push (path: curUrl)

      # 刷新页面，设置当前菜单对应页面样式
      setCurNavStyle: () ->
        self = @
        self.curUrl = window.location.href

        if 0 <= self.curUrl.indexOf('user_info')
          self.curMenu = 0
        if 0 <= self.curUrl.indexOf('info_prod')
          self.curMenu = 1
        if 0 <= self.curUrl.indexOf('info_order')
          self.curMenu = 2
        if 0 <= self.curUrl.indexOf('custom_prod')
          self.curMenu = 3

      getUserInfo: () ->
        self = @
        user_info_str = sessionStorage.getItem 'userInfo'
        self.userInfo = JSON.parse user_info_str

        # 查询客户基金
        self.queryInfoFund()

      # 查询基金
      queryInfoFund: () ->
        self = @
        params =
          client_id: "",
          id_kind: self.userInfo?.id_kind,
          id_no: self.userInfo?.id_no,
          money_type: "0",
          dsorgan_flag: "0",
          agency_no: "GF9",
          prodta_no: "87"

        return infoSideApi.queryInfoFund params
          .then (res) ->
            self.fundInfo = res?.data?.table_data[0]
          .catch (err) ->
            console.log 'err:', err

    # 组件初始化执行
    mounted: () ->
      self = @

      # 获取用户信息
      self.getUserInfo()

      # 设置菜单选中状态
      self.setCurNavStyle()